package be.idamf.flash.reflection
{
	import be.idamf.flash.common.IDisposable;
	
	import mx.rpc.IResponder;
	
	import org.flexunit.asserts.*;

	public class ReflectionTest
	{
		protected var subject:Class;
		protected var object:Object;
		
		public function ReflectionTest()
		{
		}

		[Before]
		public function setUp():void
		{
			subject = TestObject;
			object = new subject();
		}

		[After]
		public function tearDown():void
		{
			subject = null;
			object = null;
		}

		[Test]
		public function testAccessors():void
		{
			var accessors:Array;
			
			accessors = getAccessors(subject);
			assertEquals(4, accessors.length);
			
			accessors = getAccessors(object);
			assertEquals(3, accessors.length);
		}
		
		[Test]
		public function testInterfaces():void
		{
			var interfaces:Array;
			
			interfaces = getInterfaces(subject);
			assertEquals(0, interfaces.length);
			
			interfaces = getInterfaces(object);
			assertEquals(2, interfaces.length);
		}
		
		[Test]
		public function testMethods():void
		{
			var methods:Array;
			
			methods = getMethods(subject);
			assertEquals(4, methods.length);
			
			methods = getMethods(object);
			assertEquals(6, methods.length);
		}
		
		[Test]
		public function testVariables():void
		{
			var variables:Array;
			
			variables = getVariables(subject);
			assertEquals(2, variables.length);
			
			variables = getVariables(object);
			assertEquals(2, variables.length);
		}

		[Test]
		public function testImplementation():void
		{
			assertTrue(isImplementationOf(object, IDisposable));
			assertTrue(isImplementationOf(object, "be.idamf.flash.common::IInitializable"));
			assertFalse(isImplementationOf(object, IResponder));
			assertFalse(isImplementationOf(object, "foo"));
		}
	}
}

import be.idamf.flash.common.IDisposable;
import be.idamf.flash.common.IInitializable;

internal class TestObject implements IDisposable, IInitializable
{
	public static const PUBLIC_STATIC_CONST:String = "PUBLIC_STATIC_CONST";
	private static const PRIVATE_STATIC_CONST:String = "PRIVATE_STATIC_CONST";
	
	public static var public_static_var:String = "public_static_var";
	private static var private_static_var:String = "private_static_var";
	
	public static function get readwrite_static_accessor():String
	{
		return "readwrite";
	}
	
	public static function set readwrite_static_accessor(value:String):void
	{
	}
	
	public static function get readonly_static_accessor():String
	{
		return "readonly";
	}
	
	public static function set writeonly_static_accessor(value:String):void
	{
	}
	
	public static function staticMethod(arg:String):String
	{
		return arg;
	}

	protected static function staticProtectedMethod(arg:String):String
	{
		return arg;
	}
	
	public const PUBLIC_CONST:String = "PUBLIC_CONST";
	private const PRIVATE_CONST:String = "PRIVATE_CONST";
	
	public var public_var:String = "public_var";
	private var private_var:String = "private_var";
	
	public function TestObject(foobar:String = null)
	{
	}
	
	public function get readwrite_accessor():String
	{
		return "implicit_accessor";
	}
	
	public function set readwrite_accessor(value:String):void
	{
	}
	
	public function get readonly_accessor():String
	{
		return "readonly";
	}
	
	public function set writeonly_accessor(value:String):void
	{
	}
	
	public function instanceMethod(arg:String):String
	{
		return arg;
	}

	protected function instanceProtectedMethod(arg:String):String
	{
		return arg;
	}
	
	public function initialize():void
	{
	}
	
	public function dispose():void
	{
	}
}